package com.liuyucheng.tcpudp.tcp;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author LiuYuCheng
 * @date 2023年06月06日 22:47
 */
public class TCPDemo {
    public static void main(String[] args) throws IOException {
        //获取当前主机ip
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        while (true) {
            //创建发送端对象（客户端） 指定主机上的端口号
            Socket s = new Socket(hostAddress, 10086);
            System.out.println("请输入内容");
            Scanner sc = new Scanner(System.in);
            String s1 = sc.nextLine();
            //获取输出流对象写数据
            OutputStream out = s.getOutputStream();
            out.write(s1.getBytes());
            //关闭资源
            s.close();
        }

    }
}